﻿using System;
using System.Linq;
using Sales.Properties;

namespace Sales
{
    internal static class Years
    {
        private static short _item = Items[0];

        public static short Item
        {
            get { return _item; }
            set
            {
                if (_item == value) return;
                if (Items.Contains(value) == false) throw new Exception("値が不正です");
                _item = value;

            }
        }

        private static short[] _items;

        public static short[] Items
        {
            get { return _items ?? (_items = CreateItems()); }
        }

        private static short[] CreateItems()
        {
            int minYear = Settings.Default.StartYear;
            var maxYear = DateTime.Now.Year;
            return Enumerable.Range(0, maxYear - minYear + 1).Select(c => Convert.ToInt16(c + minYear)).ToArray();
        }
    }
}
